package com.lagou.util;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * 获取post请求体的json字符串
 */
public class GetPostJson {
	public static String getPostJson(HttpServletRequest req) throws IOException {
		StringBuffer sb = new StringBuffer();
		String line = null;
		BufferedReader reader = req.getReader();
		while ((line = reader.readLine()) != null)  {
			sb.append(line);
		}
		String jsonString = sb.toString().replaceAll("\\s","").replaceAll("\n","");
		if(null != reader){
			reader.close();
		}
		return jsonString;
	}
}
